package com.ldx.java_chatroom.mapper;

import com.ldx.java_chatroom.model.Friend;
import com.ldx.java_chatroom.model.MessageSession;
import com.ldx.java_chatroom.model.item.MessageSessionUserItem;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageSessionMapper {
    //1.根据userId查sessionId列表
    @Select("SELECT sessionId FROM message_session WHERE sessionId in" +
            "(select sessionId FROM message_session_user WHERE userId = #{userId}) ORDER BY lastTime desc;")
    List<Integer> getSessionIdByUserId(int userId);

    //2.根据sessionId查friendId,friendName;
    @Select("select userId as friendId,userName as friendName from user where userId in " +
            "(select userId from message_session_user where sessionId = #{sessionId}) and userId != #{userId}")
    List<Friend> getFriendListBySessionId(int sessionId,int userId);

    int addMessageSession(MessageSession messageSession);
    @Insert("insert into message_session_user values (#{sessionId},#{userId})")
    int addMessageSessionUser(MessageSessionUserItem item);
    @Select("select userId from message_session_user where sessionId = #{sessionId}")
    List<Integer> getAllUsersBySessionId(int sessionId);


}
